package cn.xiaomubiao.oschine.adapter;

import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.xiaomubiao.oschine.R;
import cn.xiaomubiao.oschine.base.BaseRecyclerViewAdapter;
import cn.xiaomubiao.oschine.bean.Active;
import cn.xiaomubiao.oschine.bean.ActiveList;
import de.hdodenhof.circleimageview.CircleImageView;

import static cn.xiaomubiao.oschine.R.drawable.v;
import static cn.xiaomubiao.oschine.util.UIUtils.getContext;

/**
 * Created by hasee on 2017/4/8.
 */

public class FriendRecylerAdapter extends BaseRecyclerViewAdapter {

    private List<Active> mActives;

    public FriendRecylerAdapter( List<Active> activeList ) {
        mActives = activeList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder( ViewGroup parent, int viewType ) {
        View itemView = LayoutInflater.from(getContext()).inflate(R.layout.view_friend_item, parent, false);
        ViewHolder viewHolder = new ViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder( RecyclerView.ViewHolder holder, int position ) {
        super.onBindViewHolder(holder, position);
        ViewHolder vH = (ViewHolder) holder;

        Active active = mActives.get(position);
        //设置头像
        Glide.with(getContext()).load(active.getPortrait()).into(vH.mIvFriendsIcon);
        //设置用户名
        vH.mTvFriendsName.setText(active.getAuthor());
        //设置时间
        vH.mTvFriendsDate.setText(active.getPubDate());
        //设置内容
        vH.mTvFriendsTalk.setText(Html.fromHtml(active.getMessage()));
        //设置图片
        if(active.getTweetimage().length() > 0) {
            vH.mIvFriendsImg.setVisibility(View.VISIBLE);
            Glide.with(getContext()).load(active.getTweetimage()).into(vH.mIvFriendsImg);
        } else {
            vH.mIvFriendsImg.setVisibility(View.GONE);
        }




    }

    @Override
    public int getItemCount() {
        return mActives != null ? mActives.size() : 0;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_friends_icon)
        CircleImageView mIvFriendsIcon;
        @BindView(R.id.tv_friends_name)
        TextView mTvFriendsName;
        @BindView(R.id.tv_friends_state)
        TextView mTvFriendsState;
        @BindView(R.id.tv_friends_talk)
        TextView mTvFriendsTalk;
        @BindView(R.id.tv_friends_date)
        TextView mTvFriendsDate;
        @BindView(R.id.iv_friends_img)
        ImageView mIvFriendsImg;
        @BindView(R.id.tv_friends_discuss)
        TextView mTvFriendsDiscuss;
        @BindView(R.id.iv_friends_phone)
        ImageView mIvFriendsPhone;
        @BindView(R.id.tv_friends_phone)
        TextView mTvFriendsPhone;

        public ViewHolder( View itemView ) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
